package cn.tedu.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

//测试 mybatis
public class TestMybatis {
    public static void main(String[] args) throws IOException {
        //        加载核心配置文件mybatis-config.xml
        InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
        //        创建会话工厂
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        //        创建会话
        SqlSession session = factory.openSession();
        //        执行SQL
        //        session.selectList(namespace的值.sql的id);
        List<User> list = session.selectList("userMapperNS.getAll");
        //        处理返回值
        for (User u : list) {
            System.out.println(u);
        }



    }
}